package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysCourseFavorites;
import com.hl.sfzy.mapper.SysCourseFavoritesMapper;
import com.hl.sfzy.service.SysCourseFavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysCourseFavoritesServiceImpl
 * @date 2024/7/13 10:11
 */

@Service("sysCourseFavoritesService")
public class SysCourseFavoritesServiceImpl implements SysCourseFavoritesService {
    @Autowired
    private SysCourseFavoritesMapper sysCourseFavoritesMapper;

    @Override
    public int add(SysCourseFavorites entity) {
        return sysCourseFavoritesMapper.insert(entity);
    }

    @Override
    public int remove(Integer id) {
        return sysCourseFavoritesMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysCourseFavoritesMapper.deleteBatch(ids);
    }

    @Override
    public int edit(SysCourseFavorites entity) {
        return 0;
    }

    @Override
    public List<SysCourseFavorites> find(SysCourseFavorites entity) {
        return sysCourseFavoritesMapper.select(entity);
    }

    @Override
    public SysCourseFavorites findById(Integer id) {
        return sysCourseFavoritesMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysCourseFavorites entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysCourseFavorites> list = sysCourseFavoritesMapper.select(entity);
        PageInfo<SysCourseFavorites> pageInfo = new PageInfo<>(list);
        Map<String,Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        return map;
    }

    @Override
    public Map<String, Object> findStatus(Integer pageNum, Integer pageSize,Integer status,SysCourseFavorites entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysCourseFavorites> list = sysCourseFavoritesMapper.selectByStatus(status,entity);
        PageInfo<SysCourseFavorites> pageInfo = new PageInfo<>(list);
        Map<String,Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        return map;
    }
}
